<template>
  <div class="app-container">
    <!-- 基础信息 -->
    <h5 class="titleInfo">基础信息</h5>
    <el-form ref="form"  :model="list" :rules="rules" label-width="130px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="手机号" prop="username">
            <el-input v-model="list.username" :disabled="this.$route.name=='designerManageInfo'" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="昵称" prop="nickName">
            <el-input v-model="list.nickName" :disabled="this.$route.name=='designerManageInfo'" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="姓名">
            <span class="spanToInput">{{ list.realname | filterNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="交钱分公司">
            <span class="spanToInput">{{ list.branchName | filterNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="级别">
            <span class="spanToInput">{{list.roleId | roleFn}}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="账户类型">
            <span class="spanToInput">{{ list.accountType | typeNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="加盟金额" prop="joinAmount">
            <!-- <el-input v-model="valnew"></el-input>  -->
            <el-input v-model="list.joinAmount" :disabled="this.$route.name=='designerManageInfo'" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="推荐码">
            <span class="spanToInput">{{ list.superCode | filterNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="签约类型">
            <el-select v-model="list.signType" :disabled="true">
              <el-option label="赠送" :value="1" />
              <el-option label="购买" :value="2" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col v-if="list.signType==1" :span="12">
          <el-form-item label="回款">
            <span v-if="list.returnMoney" v-html="list.returnMoney==1?'是':'否'" />
          </el-form-item>
        </el-col>
        <el-col v-if="list.signType==1" :span="12">
          <el-form-item label="回款备注">
            <span>{{ list.returnRemark }}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 推荐人信息 -->
      <div class="divBar" />
      <h5 class="titleInfo">推荐人信息</h5>

      <el-row>
        <el-col :span="12">
          <el-form-item label="推荐人姓名">
            <span class="spanToInput">{{ list.referName | filterNull }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="推荐人手机号">
            <span class="spanToInput">{{ list.referPhone | filterNull }}</span>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 实名认证信息 -->
      <div class="divBar" />
      <h5 class="titleInfo">实名认证信息</h5>

      <el-row>
        <el-col :span="12">
          <el-form-item label="证件类型">
            <span v-if="list.userIdentityAuth">{{ list.userIdentityAuth.identityType | cardNull }}</span>
            <span v-else>暂无数据</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="证件号码">
            <span
              v-if="list.userIdentityAuth"
              class="spanToInput"
            >{{ list.userIdentityAuth.identity | filterNull }}</span>
            <span v-else>暂无数据</span>
          </el-form-item>
        </el-col>
      </el-row>

      <!-- 银行卡信息 -->
      <div class="divBar" />
      <h5 class="titleInfo">银行卡信息</h5>
      <el-row v-for="(item, index) in list.banksDTOList" :key="index">
        <el-col :span="12">
          <el-form-item label="银行名称">
            <span class="spanToInput">{{ item.name }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="银行卡号">
            <span class="spanToInput">{{ item.card }}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
        <el-button
          v-if="this.$route.name !=='designerManageInfo'"
          type="primary"
          @click="submitFn('form')"
        >立即提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { getList, getInfo, modifyUserServerInfo } from "@/api/designerManage";
// 手机号正则
const phoneReg = (rule, value, callback) => {
  if (!value) {
    return callback(new Error("请输入会员手机号"));
  } else {
    const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    if (reg.test(value)) {
      callback();
    } else {
      return callback(new Error("手机格式错误"));
    }
  }
};
export default {
  name: "DesignerManageEdit",
  filters: {
    filterNull(e) {
      if (!e) {
        return "暂无";
      } else {
        return e;
      }
    },
    cardNull(e) {
      return window.helper.cardType(String(e));
    },
    typeNull(e) {
      return window.helper.accountType(String(e));
    },
    roleFn(e) {
      return window.helper.roleFn(String(e));
    }
  },
  data() {
    return {
      form: {},
      list: {
        username: "",
        nickName: "",
        referName: "",
        referPhone: "",
        banksDTOList: []
      },
      rules: {
        username: [
          { required: true, message: "请输入手机号", trigger: "blur" }
        ],
        nickName: [{ required: true, message: "请输入昵称", trigger: "blur" }],
        joinAmount: [
          { required: true, message: "请输入加盟金额", trigger: "blur" }
        ]
      },
      userId: null
    };
  },
  created() {
    this.form = JSON.parse(this.$route.query.userId);
    this.userId = this.form.userId;

    const datas = {
      userId: this.form.userId
    };
    getInfo(datas).then(res => {
      if (res.data.data) {
        res.data.data.banksDTOList = res.data.data.banksDTOList
          ? res.data.data.banksDTOList
          : [];
        this.list = res.data.data;
      }

      console.log(res);
    });
    console.log(2222, this.$route.name);
  },
  methods: {
    submitFn(e) {
      console.log(123, this.form);
      //   if (!this.list.username) {
      //     this.$message.error("必填项请填写完整");
      //     return;
      //   }
      this.$refs[e].validate(valid => {
        if (valid) {
          const datas = { ...this.list };

          modifyUserServerInfo(datas)
            .then(res => {
              if (!res.data.code) {
                this.$message({
                  showClose: true,
                  message: "修改成功",
                  type: "success"
                });
                this.$router.push("/designerManageIndex");
              } else {
                this.$message({
                  showClose: true,
                  message: res.data.msg,
                  type: "warning"
                });
              }
            })
            .catch(error => {
              this.$message.error(error);
            });
        } else {
          this.$message({
            message: "必填项不能为空",
            type: "warning"
          });
          return false;
        }
      });
    }
  }
};
</script>
<style scoped>
.app-container {
  padding: 0px !important;
}
</style>

